//退款详情展示
function showDetail(refundId) {
    $.ajax({
        url : "refund/detail",
        async : true,
        type : "GET",
        data : {
            "refundId" : refundId
        },
        // 成功后开启模态框
        success : queryDetail,
        error : function(res) {
            alert("退款详情信息获取失败");
        },
        dataType : "json"
    });
}
function queryDetail(res) {
    if(res.code!=0){
        alert(res.msg);
    }
    var goods = res.data.goods;
    var orders = res.data.orders;
    var refund = res.data.refund;
    var wxUser = res.data.wxUser;
    $("#refundId").text(refund.refundId);
    $("#refundReason").text(refund.refundReason);
    $("#ordersId").text(orders.ordersId);
    var ordersTypeName;
    switch (orders.ordersType) {
        case 0: ordersTypeName="普通商品"; break;
        case 1: ordersTypeName="开通会员"; break;
        case 2: ordersTypeName="卡券"; break;
        case 3: ordersTypeName="充值"; break;
        case 4: ordersTypeName="秒杀"; break;
        case 5: ordersTypeName="拍卖"; break;
        default: ordersTypeName="其他";
    }
    $("#ordersType").text(ordersTypeName);
    $("#ordersTime").text(orders.ordersTime);
    $("#goodsId").text(goods.goodsId);
    $("#goodsName").text(goods.goodsName);
    $("#wxUserId").text(wxUser.wxUserId);
    $("#nickname").text(wxUser.nickname);
    // 显示模态框
    $('#detailModal').modal('show');
}


//通过退款
function showAgree(ordersId) {
    if (confirm("是否确认通过退款？")) {
        $.ajax({
            type: 'POST',
            url: 'wxpay/refund/orders',
            dataType: 'json',
            data: {
                "ordersId": ordersId
            },
            error: function (request) {
                alert("未知错误，退款失败");
            },
            success: function (res) {
                if (res.code == 0) {
                    alert("退款发起成功");
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }
}

//拒绝退款
function showReject(refundId) {
    if (confirm("是否确认拒绝退款？")) {
        $.ajax({
            type: 'get',
            url: 'refund/reject',
            dataType: 'json',
            data: {
                "refundId": refundId
            },
            error: function (request) {
                alert("未知错误，拒绝退款失败");
            },
            success: function (res) {
                if (res.code == 0) {
                    alert("拒绝退款成功");
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }
}
